// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './stroe'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// import { Pagination } from 'element-ui';
import axios from 'axios'
import * as echarts from "echarts";
import "echarts/theme/macarons.js";
import "echarts-wordcloud"
Vue.use(ElementUI);
// Vue.use(Pagination);
import { tansParams, blobValidate } from "@/utils/ruoyi";
import commonApi from './commonApi'
// 全局方法挂载
Vue.prototype.$echarts = echarts;
Vue.prototype.commonApi = commonApi;
// 分页组件
import Pagination from "./components/Pagination";
Vue.component("Pagination", Pagination);
Vue.prototype.axios = axios;
Vue.prototype.tansParams = tansParams;
Vue.prototype.blobValidate = blobValidate;
//线上部署配置，开发时注释下面一行代码
//axios.defaults.baseURL= '/prod-api/'
// axios.defaults.headers.post['Content-Type'] = 'application/json';

Vue.config.productionTip = false
Vue.prototype.cutMoneyFiter = (amount) => {
	if(!amount) {
		return "0"
	}
	//强制保留两位小数
	let f = parseFloat(amount);
	if (isNaN(f)) return false;
		f = Math.round(amount * 100) / 100;
	let s = f.toString();
	// let rs = s.indexOf('.');
	// if (rs < 0) {
	// 	rs = s.length;
	// 	s += '.';
	// }
	// while (s.length < (rs + 1) + 2) {
	// 	s += '0';
	// }
	//每三位用一个逗号隔开
	let leftNum=s.split(".")[0];
	let rightNum="."+s.split(".")[1];
	let result;
	//定义数组记录截取后的价格
	let resultArray=new Array();
	if(leftNum.length>3){
		let i=true;
		while (i){
			resultArray.push(leftNum.slice(-3));
			leftNum=leftNum.slice(0,leftNum.length-3);
			if(leftNum.length<4){
				i=false;
			}
		}
		//由于从后向前截取，所以从最后一个开始遍历并存到一个新的数组，顺序调换
		let sortArray=new Array();
		for(let i=resultArray.length-1;i>=0;i--){
			sortArray.push(resultArray[i]);
		}
		// result=leftNum+","+sortArray.join(",")+rightNum;
		result=leftNum+","+sortArray.join(",");
	}else {
		result=s;
	}
	return result;
}
Vue.prototype.$addStorageEvent = function (type, key, data) {
	if (type === 1) {
	  // 创建一个StorageEvent事件
	  var newStorageEvent = document.createEvent("StorageEvent");
	  const storage = {
		setItem: function (k, val) {
		  localStorage.setItem(k, val);
		  // 初始化创建的事件
		  newStorageEvent.initStorageEvent(
			"setItem",
			false,
			false,
			k,
			null,
			val,
			null,
			null
		  );
		  // 派发对象
		  window.dispatchEvent(newStorageEvent);
		},
	  };
	  return storage.setItem(key, data);
	} else {
	  // 创建一个StorageEvent事件
	  var newStorageEvent = document.createEvent("StorageEvent");
	  const storage = {
		setItem: function (k, val) {
		  sessionStorage.setItem(k, val);
		  // 初始化创建的事件
		  newStorageEvent.initStorageEvent(
			"setItem",
			false,
			false,
			k,
			null,
			val,
			null,
			null
		  );
		  // 派发对象
		  window.dispatchEvent(newStorageEvent);
		},
	  };
	  return storage.setItem(key, data);
	}
  };
/* eslint-disable no-new */
new Vue({
  el: '#app',
  axios,
  store,
  router,
  components: { App },
  template: '<App/>'
})
